package chapter6.section1;

//程序6-1a：一个账户类，用做超类
public class Account {
	private String id;// 账户id，唯一性的标识
	private String name;// 账户拥有人的姓名
	private int balance;// 余额

	public Account(String id, String name, int balance) {
		this.id = id;
		this.name = name;
		this.balance = balance;
	}

	public Account(String id, String name) {
		this.id = id;
		this.name = name;
		this.balance = 1000;// 给账户一个默认的初始余额
	}

	// 取款的方法,返回本次取出的金额，如果为0，表示余额不足
	public int withdraw(int amount) {
		int result = 0;
		if (this.balance >= amount) {
			this.balance = this.balance - amount;
			result = amount;
		}
		return result;
	}

	public int getBalance() {
		return this.balance;
	}

	public void setBalance(int balance) {
		this.balance = balance;
	}
	// 以下可以自行添加关于属性访问的getter和setter方法及其他方法
}
